/**
 * @description:TODO
 * @author: cai
 * @time:2017年10月13日上午11:54:46
 */
package com.pos.modules;

import android.app.Dialog;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;

import com.basewin.aidl.OnPrinterListener;
import com.basewin.services.ServiceManager;
import com.pos.BaseActivity;
import com.pos.R;
import com.pos.modules.cashier.AccountActivity;
import com.pos.modules.cashier.adapter.GoodsListAdapter;
import com.pos.modules.cashier.adapter.GoodsListAdapter.DoAction;
import com.pos.modules.cashier.bean.GoodsBean;
import com.pos.net.base.Request.Method;
import com.pos.net.netparam.NetParams;
import com.pos.net.netparam.RequestUrls;
import com.pos.net.request.interfa.BaseRequestListener;
import com.pos.net.request.interfa.JsonRequestListener;
import com.pos.set.AppSet;
import com.pos.toolbox.FinancialUtils;
import com.pos.widgets.AbsAdapter;
import com.pos.widgets.InnerListview;
import com.pos.widgets.ScanGunKeyEventHelper;
import com.pos.widgets.dialog.CommonDialog;
import com.pos.widgets.swipe.CustomSwipeListView;
import com.zng.common.PrintPowerOnAndOffUtils;
import com.zng.common.PrintUtils;
import com.zng.common.contact.PayContacts;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @hdd 退货按钮
 */
public class SaleReturnActivity extends BaseActivity
		implements OnClickListener, ScanGunKeyEventHelper.OnScanSuccessListener {
	private String goodsCode;
	private List<GoodsBean> goodsList;
	private GoodsListAdapter adapter;
	private CustomSwipeListView swipeListView;
	private TextView text_total, text_submit;
	private EditText edit_code;
	private RelativeLayout relative_submit;
	private long totalFen = 0;
	private CommonDialog commonDialog;
	private ScanGunKeyEventHelper mScanGunKeyEventHelper;
	private EditText edit_member;
	private Dialog memberDialog,dialog_money;
	private View memberView,viewmoney;
	private LayoutInflater inflater;
	private TextView cancel,config,text_common_title, text_common_right, wx, pay, bank, pay_type, order_price, order_time, order_paybillnumber, order_code, salereturn;
	private LinearLayout linear_title_back;
	private int paytype = 1;
	private String actTotalAmount = "";
	private String payBillNumber = "";
	private InnerListview listview;
	private AbsAdapter<GoodsBean> listview_adapter;
	private List<GoodsBean> datas;
	JSONObject printJson = new JSONObject();
	private PrinterListener printer_callback = new PrinterListener();
	private String money="1";
	@Override
	public void initView() {
		setContentView(R.layout.activity_sale_return);
		listview = bindId(R.id.innerlistview);
		datas = new ArrayList<>();
		listview_adapter = new AbsAdapter<GoodsBean>(this, datas, R.layout.item_goods) {
			@Override
			public void showData(ViewHolder vHolder, GoodsBean data, int position) {
				TextView name = (TextView) vHolder.getView(R.id.name);
				TextView price = (TextView) vHolder.getView(R.id.price);
				TextView num = (TextView) vHolder.getView(R.id.num);
				name.setText(data.getName());
				price.setText(FinancialUtils.fen2yuan(data.getPrice()) + "");
				num.setText(data.getNum()+"");

			}
		};
		listview.setAdapter(listview_adapter);
		order_code = bindId(R.id.ordercode);
		pay_type = bindId(R.id.paytype);
		order_paybillnumber = bindId(R.id.paybillnumber);
		order_price = bindId(R.id.orderprice);
		order_time = bindId(R.id.ordertime);
		swipeListView = bindId(R.id.swipeListView);
		text_total = bindId(R.id.text_total);
		edit_code = bindId(R.id.edit_code);
		// text_search = bindId(R.id.text_search);
		text_submit = bindId(R.id.text_submit);
		relative_submit = bindId(R.id.relative_submit);
		memberDialog = new Dialog(mContext, R.style.dialog);
		dialog_money = new Dialog(mContext, R.style.dialog);
		inflater = LayoutInflater.from(mContext);
		memberView = inflater.inflate(R.layout.dialog_member_layout, null);
        viewmoney = inflater.inflate(R.layout.money, null);
		edit_member = bindId(memberView, R.id.edit_member);
        cancel = bindId(viewmoney, R.id.cancel);
        config = bindId(viewmoney, R.id.config);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog_money.dismiss();
            }
        });
        config.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posSaleReturn, Method.POST,
                        NetParams.posSaleReturn(mContext, edit_code.getText().toString().trim()), 2, listenerWx);
            }
        });
		text_common_title = bindId(R.id.text_common_title);
		linear_title_back = bindId(R.id.linear_title_back);
		text_common_right = bindId(R.id.text_common_right);
		memberDialog.setContentView(memberView);
		dialog_money.setContentView(viewmoney);
		Window dialogWindow = memberDialog.getWindow();
		WindowManager m = getWindowManager();
		Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
		WindowManager.LayoutParams p = dialogWindow.getAttributes();
		// p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6
		p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65
		dialogWindow.setAttributes(p);

        Window dialogWindow1 = dialog_money.getWindow();
        WindowManager m1 = getWindowManager();
        Display d1 = m1.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p1 = dialogWindow.getAttributes();
        // p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6
        p1.width = (int) (d1.getWidth() * 0.8); // 宽度设置为屏幕的0.65
        dialogWindow1.setAttributes(p1);
		memberDialog.setCancelable(false);
		dialog_money.setCancelable(false);
		text_submit.setOnClickListener(this);
		salereturn = bindId(R.id.tv_wx);
        /*pay = bindId(R.id.tv_pay);
        bank = bindId(R.id.tv_bank);*/
		salereturn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
                /*
                * 请求参数：
            “ORDER_MONEYS”退款金额（以分为单位,如 2分则传入“2”）
            “ORDER_NUMBER”交易凭证号（支付时小票打印的交易凭证号）
            “PAY_TYPE”支付类型（微信—“3”，支付宝—“5”）
                *
                * */
				if (paytype == 4) {
					Intent intent = new Intent();
					intent.setAction("cn.zng.pay.action");
					intent.addCategory("cn.zng.pay.category");
					intent.putExtra(PayContacts.REQUEST_DATA, "{\"amount\":\"" + actTotalAmount + "\",\"trade_type\":\"002\",\"voucher_no\":\"" + payBillNumber + "\"} ");
					startActivityForResult(intent, 100);

				} else {
					netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posSaleReturn, Method.POST,
							NetParams.posSaleReturn(mContext, edit_code.getText().toString().trim()), 2, listenerWx);
				}
			}
		});
     /*   pay.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("cn.pospal.www.zng.pos.refund");
                intent.addCategory("cn.pospal.www.zng.pos.refund.category");
                intent.putExtra("ORDER_MONEYS", "2");
                intent.putExtra("ORDER_NUMBER", "1503888635987453150025");
                intent.putExtra("PAY_TYPE", "5");
                startActivityForResult(intent, 101);
            }
        });
        bank.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

               *//* PayContacts.TRADE_TYPE 消费撤销
               PayContacts.VOID_TYPE PayContacts.AMOUNT 交易金额(以分为单位,比如2分)
                PayContacts.VOUCHER_NO 消费凭证号*//*


            }
        });*/

	}
	public class PrinterListener implements OnPrinterListener {

		@Override
		public void onStart() {
			// TODO 打印开始
			// Print start
			// Log.d(TAG, getStr(R.string.print_start));
			// sb.append(getStr(R.string.print_start) + "\n");
			// showText(sb);
			Log.e(Tag, "PrinterListener onStart");
		}

		@Override
		public void onFinish() {
			// TODO 打印结束
			// End of the print
			// Log.d(TAG, getStr(R.string.print_end));
			// sb.append(getStr(R.string.print_end) + "\n");
			// showText(sb);
			Log.e(Tag, "PrinterListener onFinish");

		}

		@Override
		public void onError(int errorCode, String detail) {
			// TODO 打印出错
			// print error
			// Log.d(TAG, getStr(R.string.print_error) + " errorcode = " +
			// errorCode + " detail = " + detail);
			// sb.append(getStr(R.string.print_error) + errorCode + " detail = "
			// + detail + "\n");
			// showText(sb);
			Log.e(Tag, "PrinterListener onError " + detail);

		}
	};
	@Override
	public void initData() {
		commonDialog = new CommonDialog(mContext);
		AppSet.cashierActivities.add(this);
		mScanGunKeyEventHelper = new ScanGunKeyEventHelper(this);
		registerBoradcastReceiver();
		linear_title_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				commonDialog.showDialog("确定退出退货？", "确定", new OnClickListener() {

					@Override
					public void onClick(View v) {
						commonDialog.dismissDialog();
						finish();

					}
				});

			}
		});
		text_common_right.setVisibility(View.GONE);

		// ActionBarManager.init(this, "收银台", true, R.drawable.image_scanner,
		// new View.OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// startActivityForResult(new Intent(mContext, ScannerActivity.class),
		// 0);
		//
		// }
		// });
		Log.e(Tag, "第一次进入");
		goodsList = (ArrayList<GoodsBean>) getIntent().getSerializableExtra("goodsList");
		if (goodsList == null) {
			goodsList = new ArrayList<>();
		}
		adapter = new GoodsListAdapter(mContext, goodsList, new DoAction() {

			@Override
			public void onMinus(int position) {
				if (goodsList.get(position).getNum() > 1) {
					goodsList.get(position).setNum(goodsList.get(position).getNum() - 1);
					adapter.notifyDataSetChanged();
					dealAccount();
				}

			}

			@Override
			public void onDelete(int position) {
				goodsList.remove(position);
				adapter.notifyDataSetChanged();
				dealAccount();
			}

			@Override
			public void onAdd(int position) {
				goodsList.get(position).setNum(goodsList.get(position).getNum() + 1);
				adapter.notifyDataSetChanged();
				dealAccount();
			}
		});
		swipeListView.setAdapter(adapter);
		dealAccount();
//		edit_code.setFocusable(true);
//		edit_code.setFocusableInTouchMode(true);
//		edit_code.requestFocus();
//		edit_code.setVisibility(View.GONE);
	}

	@Override
	public void initListener() {

		edit_code.setOnEditorActionListener(new OnEditorActionListener() {

			@Override
			public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

				goodsCode = edit_code.getText().toString();
				if (TextUtils.isEmpty(goodsCode)) {
					showShortToast("请输入商品码");
					return false;
				}
				Log.e("onEditorAction", "onEditorAction*******goodsCode=" + goodsCode + "******");

				netRequest.startRequest(RequestUrls.hostUrl + "posQueryOrderDetail", Method.POST,
						NetParams.posQuerySalereturnOrderDetail(mContext, goodsCode), 0, listener);
				return true;
			}
		});
		// text_search.setOnClickListener(this);

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);


		if (requestCode == 101) {
            /*智能果乐 POS SDK 接口说明
            北京智能果技术有限公司内部文档（ZHINENGGUO-GDS-1.0.0） Zhinengguo Technology Co.,Ltd 第 51 页 共 52 页*/
			if (resultCode == 201) {
				String returnMsg = data.getStringExtra("order_return_data");
				Log.e("lss", " returnMsg = " + returnMsg);
			}
		} else if (resultCode == RESULT_OK) {
			if (data != null) {
				String dealData = data.getStringExtra(PayContacts.RETURN_DATA);
				if (dealData != null) {
					//   show_result.setText(dealData);
					Log.e("TAG", "onActivityResult: " + dealData);
				}
				netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posSaleReturn, Method.POST,
						NetParams.posSaleReturn(mContext, edit_code.getText().toString().trim()), 2, listenerWx);
			}
		} else if (resultCode == RESULT_CANCELED) {
			if (data != null) {
				String errorInfo = data.getStringExtra(PayContacts.RETURN_DATA);
				Log.e("TAG", "onActivityResult: " + errorInfo);
				//  show_result.setText(errorInfo);
			}
		}

		/*if (resultCode == RESULT_OK) {
			if (requestCode == 0) {
				goodsCode = data.getStringExtra("goodsCode");
				Log.e("goodsCode", "goodsCode=" + goodsCode);
				netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posQueryGoodsByCode, Method.POST,
						NetParams.posQueryGoodsByCode(mContext, goodsCode), 0, listener);
			} else if (requestCode == 1) {
				goodsList.clear();
				adapter.notifyDataSetChanged();
				memberCode = "";
				memberPayToken = "";
				memberName = "";
				levelName = "";
				memberScore = "";
				memberBalance = "";
				memberPayToken = "";
				edit_code.setText("");
				edit_member.setText("");
				text_member_amount.setText("");
				text_member_credits.setText("");
				text_member_level.setText("");
				text_member_name.setText("");
				dealAccount();
			}

		}*/
	}

	/**
	 * 截获按键事件.发给ScanGunKeyEventHelper
	 *
	 * @param event
	 * @return
	 */
	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {

		if (mScanGunKeyEventHelper.isScanGunEvent(event)) {
			mScanGunKeyEventHelper.analysisKeyEvent(event);
			return true;
		}
		return super.dispatchKeyEvent(event);
	}

	@Override
	protected void onResume() {
		super.onResume();

		Log.e(Tag, "CashierActivity    onResume********");
		if (!mScanGunKeyEventHelper.hasScanGun()) {
			// Toast.makeText(mContext, "未检测到扫码枪设备", Toast.LENGTH_SHORT).show();
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		unregisterReceiver(stateChangeReceiver);
		mScanGunKeyEventHelper.onDestroy();
	}

	@Override
	public void onScanSuccess(String barcode) {
		Log.e(Tag, "onScanSuccess barcode=" + barcode);
		edit_code.setText("");
		System.out.println("************barcode=" + barcode);
		if(barcode.equals("")){
                return;
		}
		if(barcode.indexOf("-") != -1){
//包含
			goodsCode=barcode;
		}else{
//不包含
			String s= barcode.substring(0,4);
			String ss=barcode.substring(4,barcode.length()-4);
			String sss=barcode.substring(barcode.length()-4,barcode.length());
			goodsCode = s+"-"+ss+"-"+sss;
		}
		edit_code.setText(goodsCode);
	/*	if(!barcode.equals("")){
			String s= barcode.substring(0,4);
			String ss=barcode.substring(4,barcode.length()-4);
			String sss=barcode.substring(barcode.length()-4,barcode.length());
			goodsCode = s+"-"+ss+"-"+sss;
		}else{
			goodsCode=barcode;
		}*/
       /*String s= barcode.substring(0,4);
       String ss=barcode.substring(4,barcode.length()-4);
       String sss=barcode.substring(barcode.length()-4,barcode.length());*//*
		goodsCode = s+"-"+ss+"-"+sss;*/
        Log.e("TAG", "onScanSuccess: "+goodsCode );
		netRequest.startRequest(RequestUrls.hostUrl + "posQueryOrderDetail", Method.POST,
				NetParams.posQuerySalereturnOrderDetail(mContext, goodsCode), 0, listener);
	}

	private void registerBoradcastReceiver() {
		IntentFilter filter1 = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
		IntentFilter filter2 = new IntentFilter(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
		registerReceiver(stateChangeReceiver, filter1);
		registerReceiver(stateChangeReceiver, filter2);
	}

	private BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();

			if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
				// Toast.makeText(mContext, "蓝牙设备连接状态已变更",
				// Toast.LENGTH_SHORT).show();
			} else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
				// Toast.makeText(mContext, "蓝牙设备连接状态已变更",
				// Toast.LENGTH_SHORT).show();
			}
		}
	};

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}

	private void dealAccount() {
		if (goodsList.size() == 0) {
			relative_submit.setVisibility(View.GONE);
		} else {
			relative_submit.setVisibility(View.VISIBLE);
			totalFen = 0;
			for (GoodsBean item : goodsList) {
				totalFen = totalFen + item.getPrice() * item.getNum();
			}
			text_total.setText("¥" + FinancialUtils.fen2yuan(totalFen));
		}

	}

	private BaseRequestListener listener = new JsonRequestListener() {

		@Override
		public void onStart(int requestId) {

			showDialg();
		}

		@Override
		public void onError(int requestId, int errorCode, String errorMsg) {
			disMissDialog();
			if (requestId == 2) {
				memberDialog.dismiss();
				dealError(errorCode, errorMsg);
			} else {
				dealError(errorCode, errorMsg);
				edit_code.setText("");
			}

		}

		@Override
		public void onSuccess(int requestId, String url, JSONObject jsonResult) {
			Log.e("TAG", "onSuccess: " + jsonResult.toString());
			//1  没有订单
			//0  查询成功
			//payMethod  1  微信   2支付宝   3 翼支付  4 银联
			int retCode = jsonResult.optInt("retCode", 0);
			if (retCode == 0) {
				money="1";
                datas.clear();
				actTotalAmount = jsonResult.optString("actTotalAmount");//金额
				String orderCode = jsonResult.optString("orderCode");//交易号
				payBillNumber = jsonResult.optString("payBillNumber");//综合支付流水号
				String orderDatetime = jsonResult.optString("orderDatetime");//交易时间
				paytype = jsonResult.optInt("payMethod");

				order_price.setText("付款金额:" + "¥" + FinancialUtils.fen2yuan(Long.parseLong(actTotalAmount)));
				order_paybillnumber.setText("综合支付流水号:" + payBillNumber);
				order_time.setText("支付时间:" + orderDatetime);
				order_code.setText("交易号:" + orderCode);
				if (paytype == 1) {
					pay_type.setText("支付方式:微信支付");
				} else if (paytype == 2) {
					pay_type.setText("支付方式:支付宝支付");
				} else if (paytype == 3) {
					pay_type.setText("支付方式:翼支付");
				} else if(paytype==0){
					pay_type.setText("支付方式:现金支付");
				}else{
					pay_type.setText("支付方式:银联支付");
				}
				JSONArray goods = jsonResult.optJSONArray("goodsList");
				//    [{"amount":2500,"price":2500,"goodsCode":"9787510448201","count":1,"goodsName":"写给儿童的中国历史——东周知心的朋友"}
				for (int i = 0; i < goods.length(); i++) {
					GoodsBean goodBean = new GoodsBean("", goods.optJSONObject(i).optString("goodsName"),
							goods.optJSONObject(i).optLong("price", 0), goods.optJSONObject(i).optInt("count"));
					datas.add(goodBean);
				}
				listview_adapter.notifyDataSetChanged();
			}else if(retCode==2){
				{
					money="2";
					datas.clear();
					actTotalAmount = jsonResult.optString("actTotalAmount");//金额
					String orderCode = jsonResult.optString("orderCode");//交易号
					payBillNumber = jsonResult.optString("payBillNumber");//综合支付流水号
					String orderDatetime = jsonResult.optString("orderDatetime");//交易时间
					paytype = jsonResult.optInt("payMethod");

					order_price.setText("付款金额:" + "¥" + FinancialUtils.fen2yuan(Long.parseLong(actTotalAmount)));
					order_paybillnumber.setText("综合支付流水号:" + payBillNumber);
					order_time.setText("支付时间:" + orderDatetime);
					order_code.setText("交易号:" + orderCode);
					if (paytype == 1) {
						pay_type.setText("支付方式:微信支付");
					} else if (paytype == 2) {
						pay_type.setText("支付方式:支付宝支付");
					} else if (paytype == 3) {
						pay_type.setText("支付方式:翼支付");
					} else if(paytype==0){
						pay_type.setText("支付方式:现金支付");
					}else{
						pay_type.setText("支付方式:银联支付");
					}
					JSONArray goods = jsonResult.optJSONArray("goodsList");
					//    [{"amount":2500,"price":2500,"goodsCode":"9787510448201","count":1,"goodsName":"写给儿童的中国历史——东周知心的朋友"}
					for (int i = 0; i < goods.length(); i++) {
						GoodsBean goodBean = new GoodsBean("", goods.optJSONObject(i).optString("goodsName"),
								goods.optJSONObject(i).optLong("price", 0), goods.optJSONObject(i).optInt("count"));
						datas.add(goodBean);
					}
					listview_adapter.notifyDataSetChanged();
				}
			}else{
				money="1";
				Toast.makeText(SaleReturnActivity.this,"订单不存在", Toast.LENGTH_SHORT).show();

			}
			disMissDialog();


		}
	};
	private BaseRequestListener listenerWx = new JsonRequestListener() {

		@Override
		public void onStart(int requestId) {

			//  showDialg();
		}

		@Override
		public void onError(int requestId, int errorCode, String errorMsg) {
			disMissDialog();
			if (requestId == 2) {
				memberDialog.dismiss();
				dealError(errorCode, errorMsg);
			} else {
				dealError(errorCode, errorMsg);
				edit_code.setText("");
			}

		}

		@Override
		public void onSuccess(int requestId, String url, final JSONObject jsonResult) {
			Log.e("TAG", "onSuccess11111: " + jsonResult.toString());
			// disMissDialog();
			//1  没有订单
			//0  查询成功
			//payMethod  1  微信   2支付宝   3 翼支付  4 银联

			if(requestId==0){
				int retCode = jsonResult.optInt("retCode", 0);
				if (retCode == 0) {

					Toast.makeText(SaleReturnActivity.this, "退货成功", Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(SaleReturnActivity.this, "退货失败", Toast.LENGTH_SHORT).show();
				}
				//  disMissDialog();
			}else if(requestId==2){
				int retCode = jsonResult.optInt("retCode", 0);
				if(retCode==0){
					try {
						try {
							JSONArray printTest = new JSONArray();

							JSONObject json0 = new JSONObject();
							json0.put("content-type", "txt");

							json0.put("content", jsonResult.optString("printInfo"));

							//	json0.put("content", "212123123");
							json0.put("size", "2");
							json0.put("position", "left");
							json0.put("offset", "0");
							json0.put("bold", "0");
							json0.put("italic", "0");
							json0.put("height", "-1");
							printTest.put(json0);
							printJson.put("spos", printTest);
							// 设置底部空3行
							// Set at the bottom of the empty 3 rows
							com.pos.sdk.printer.PosPrinter.Parameters parameters = ServiceManager.getInstence().getPrinter()
									.getParameters();
							parameters.setPrintGray(5000);
							parameters.setPrintStep(4000);
							parameters.setPrintHeatPoint(1000);
							ServiceManager.getInstence().getPrinter().setParameters(parameters);
							ServiceManager.getInstence().getPrinter().setPrintGray(2000);
							ServiceManager.getInstence().getPrinter().printBottomFeedLine(5);
							ServiceManager.getInstence().getPrinter().print(printJson.toString(), null, printer_callback);
				/*JSONObject jsonObject=new JSONObject();
				JSONArray printTest1 = new JSONArray();

				JSONObject json01 = new JSONObject();
				json0.put("content-type", "one-dimension");
				json0.put("content", "11123123");
				json0.put("size", "2");
				json0.put("position", "left");
				json0.put("offset", "0");
				json0.put("bold", "0");
				json0.put("italic", "0");
				json0.put("height", "-1");
				jsonObject.put("spos", printTest1);
				ServiceManager.getInstence().getPrinter().print(jsonObject.toString(), null, printer_callback);*/
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					Toast.makeText(SaleReturnActivity.this, "退款成功", Toast.LENGTH_SHORT).show();
				}else{
					Toast.makeText(SaleReturnActivity.this, jsonResult.optString("msg"), Toast.LENGTH_SHORT).show();
				}

			}



		}
	};

	@Override
	public void onClick(View v) {
		switch (v.getId()) {


			default:
				break;
		}

	}

	@Override
	public void onBackPressed() {
		commonDialog.showDialog("确定退出退货？", "确定", new OnClickListener() {

			@Override
			public void onClick(View v) {
				commonDialog.dismissDialog();
				finish();

			}
		});
	}

}
